package com.ljk.util;

import java.io.File;
/**
 * 系统工具类
 * @author ljk
 * @since 2025/3/25 20:07
 */
public class SystemUtil {
    /**
     * 获取系统类型
     *
     * @return {@link OsType}
     * @author ljk
     * @since 2025/3/25 20:05
     */
    public static OsType getOsName() {
        String osName = System.getProperty("os.name").toLowerCase();
        if (osName.contains("win")) {
            return OsType.WINDOWS;
        } else if (osName.contains("nix") || osName.contains("nux") || osName.contains("aix")) {
            return OsType.LINUX;
        } else if (osName.contains("mac")) {
            return OsType.MACOS;
        } else {
            return OsType.OTHER;
        }
    }

    /**
     * 获取桌面路径
     *
     * @return 桌面路径
     * @author ljk
     * @since 2025/3/25 20:05
     */
    public static String getDesktopPath() {
        String home = System.getProperty("user.home");
        switch (getOsName()) {
            case LINUX:
                // 检查是否存在 "Desktop" 或 "桌面" 文件夹
                File desktopDir = new File(home, "Desktop");
                if (desktopDir.exists()) {
                    return desktopDir.getAbsolutePath();
                } else {
                    desktopDir = new File(home, "桌面");
                    if (desktopDir.exists()) {
                        return desktopDir.getAbsolutePath();
                    } else {
                        // 如果都不存在，返回默认的 "Desktop" 路径
                        return home + File.separator + "Desktop";
                    }
                }
            case WINDOWS:
            case MACOS:
            default:
                return home + File.separator + "Desktop";
        }
    }

    /** 系统类型枚举 */
    public enum OsType {
        WINDOWS,
        LINUX,
        MACOS,
        OTHER
    }
}
